package com.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * @Auther: ChenJinEn
 * @Date: 2020/7/6 21:04
 * @Description: //TODO
 */
public class Guess {
    public static void main(String[] args) {
        //guessNumber();
        //Arr();
        //arrToString(arr);
        //addNum();
        //随机的6位数
        //int i = (int) ((Math.random() * 9 + 1) * 100000);
        //System.out.println(getNum());
        System.out.println(((-2)>>3));
    }
    public static int getNum(){
        try {
            int i= 1/0;
            System.out.println("shsh");
            return 1;
        } catch (Exception e) {
            System.out.println("11111");
            return 2;
        } finally {
            System.out.println("无论如何都要执行");
            return 3;
        }
    }

    //存6个1-10的不重复的随机数字
    private static void addNum() {
        Random random = new Random();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            int num = random.nextInt(10) + 1;
            if (!list.contains(num)){
                list.add(num);
            }else {
                i--;
            }
        }
        System.out.println(list);
    }

    //打印数组
    private static void arrToString(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == arr[arr.length-1]){
                System.out.print(arr[i]+"]");
            }else{
                System.out.print(arr[i]+",");
            }
        }
    }

    //数组的一些小案列
    private static void Arr() {
        int[] arr = new int[]{3,4,1,2,5};
        //找最大值
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i]>max){
                max = arr[i];
            }
        }
        System.out.println("数组中的最大值是:"+max);
        //由大到小冒泡
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = i+1; j < arr.length; j++) {
                if(arr[i]<arr[j]){
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        //数组反转
        System.out.println(Arrays.toString(arr));
        for (int i = 0,j = arr.length-1; i < j; i++,j--) {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
        arrToString(arr);
    }

    //猜数字
    private static void guessNumber() {
        Random random = new Random();
        int i = random.nextInt(100)+1;
        System.out.println("请输入所猜的数字:");
        int j = 1;
        while (j <= 5){
            Scanner scanner = new Scanner(System.in);
            int i1 = scanner.nextInt();
            if (i1>i) {
                System.out.println("数字猜大了!");
            }else if(i1<i){
                System.out.println("数字猜小了");
            }else{
                System.out.println("恭喜你数字猜对了,但是并没有奖品哦!哈哈哈~~~~");
                break;
            }
            System.out.println("你还剩余"+(5-j)+"次机会可用");
            j++;
        }
    }
}
